package br.com.brazilog.security;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 
 * @author Gabriel Cardelli
 *
 */
public class ViewPageSecurityFilter implements Filter {

    public ViewPageSecurityFilter() {
        // TODO Auto-generated constructor stub
    }

	public void destroy() {
		// TODO Auto-generated method stub
	}

	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
		
//		HttpServletRequest httpRequest = (HttpServletRequest) request;
//		HttpServletResponse httpResponse = (HttpServletResponse) response;
//		HttpSession session = httpRequest.getSession(false);
//		
//		if(httpRequest.getRequestURL().toString().contains("xhtml")){
//			if(session == null){
//				httpResponse.sendRedirect("/jBiblioteca/AcessDenied.xhtml");
//			}else{
//		//		Pessoa pessoa = (Pessoa) session.getAttribute("user");
//			//	if(pessoa == null){
//					httpResponse.sendRedirect("/jBiblioteca/AcessDenied.xhtml");
//			//	}else{
//					if(pessoa instanceof Funcionario){
//						
//				//		Funcionario funcionario = (Funcionario) pessoa;
//						
//						if(funcionario.isAdmin()){
//							chain.doFilter(httpRequest, httpResponse);
//						}else{
//							httpResponse.sendRedirect("/jBiblioteca/AcessDenied.xhtml");;
//						}
//						
//					}else{
//						httpResponse.sendRedirect("/jBiblioteca/AcessDenied.xhtml");
//					}
//				}
//			}
//		}else{
//			chain.doFilter(httpRequest, httpResponse);
//		}
	}

	public void init(FilterConfig fConfig) throws ServletException {
		// TODO Auto-generated method stub
	}

}
